<?php
/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2017/12/20
 * Time: 下午2:34
 */
class Api_model extends CI_Model{
    public function __construct(){
        $this->load->database();
        $this->load->helper("common");
        $this->load->library('email');
    }

    //发送邮件
    public function send_email($sender_name, $to_email, $title, $content, $mailtype = 'html',$attach)
    {
        $this->load->library('email');
        $config['protocol'] = $this->config->item("protocol"); // 使用smtp协议
        $config['smtp_host'] = $this->config->item("smtp_host"); // smtp主机
        $config['smtp_user'] = $this->config->item("smtp_user"); // smtp用户
        $config['smtp_pass'] = $this->config->item("smtp_pass"); // 密码
        $config['crlf'] = "\r\n"; // 设置换行符
        $config['newline'] = "\r\n"; // 设置换行符
        $config['mailtype'] = $mailtype; // 设置邮件类型
        $this->email->initialize($config); // 写入配置项
        $this->email->from($this->config->item("smtp_user"), $sender_name);
        $this->email->to($to_email);
        $this->email->subject($title);
        $this->email->message($content);
        $this->email->attach($attach);
        $re = $this->email->send();
        return $re;
    }
   
}